package com.housekeeping.housekeeping.order.controller.order;

import com.housekeeping.housekeeping.order.entity.Order;
import com.housekeeping.housekeeping.order.service.OrderDetailServ;
import com.housekeeping.housekeeping.order.service.impl.OrderDetailServImpl;
import com.housekeeping.housekeeping.order.utils.ResponseCode;
import com.housekeeping.housekeeping.order.utils.ResponseEntity;
import com.housekeeping.housekeeping.order.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/order/detail")
public class OrderDetailController extends HttpServlet {
    private OrderDetailServ orderDetailServ = new OrderDetailServImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid = req.getParameter("sid");
        ResponseEntity<Order> entity = null;

        //调用业务逻辑
        try {
            Order orderContent = orderDetailServ.getOrderContent(sid);
            if (orderContent != null) {
                entity = ResponseEntity.success(orderContent);
            } else {
                entity = ResponseEntity.error(ResponseCode.ORDER_DATA_GET_ERROR);
            }
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(ResponseCode.ORDER_DATA_GET_ERROR);
        }

        //传递数据
        ResponseUtils.deliver(resp, entity);
    }
}
